<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>MrLee の Blog</title><meta name="author" content="MrLee"><meta name="copyright" content="MrLee"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="Try harder">
<meta property="og:type" content="website">
<meta property="og:title" content="MrLee の Blog">
<meta property="og:url" content="https://amasmrlee.gitee.io/page/2/index.html">
<meta property="og:site_name" content="MrLee の Blog">
<meta property="og:description" content="Try harder">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://amasmrlee.gitee.io/img/avatar/avatar.png">
<meta property="article:author" content="MrLee">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://amasmrlee.gitee.io/img/avatar/avatar.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://amasmrlee.gitee.io/page/2/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//fonts.googleapis.com" crossorigin=""/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium+Web&amp;display=swap" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'mediumZoom',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#121212","position":"bottom-left"},
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isanchor: true
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = { 
  isPost: false,
  isHome: true,
  isHighlightShrink: false,
  isToc: false,
  postUpdate: '2021-09-06 17:39:41'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
          const isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
          const isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
          const hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified

          if (t === undefined) {
            if (isLightMode) activateLightMode()
            else if (isDarkMode) activateDarkMode()
            else if (isNotSpecified || hasNoSupport) {
              const now = new Date()
              const hour = now.getHours()
              const isNight = hour <= 6 || hour >= 18
              isNight ? activateDarkMode() : activateLightMode()
            }
            window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
              if (saveToLocal.get('theme') === undefined) {
                e.matches ? activateDarkMode() : activateLightMode()
              }
            })
          } else if (t === 'light') activateLightMode()
          else activateDarkMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const fontSizeVal = saveToLocal.get('global-font-size')
    if (fontSizeVal !== undefined) {
      document.documentElement.style.setProperty('--global-font-size', fontSizeVal + 'px')
    }
    })(window)</script><meta name="generator" content="Hexo 5.4.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" data-lazy-src="/img/avatar/avatar.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">34</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">35</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">14</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="page" id="body-wrap"><header class="full_page" id="page-header" style="background-image: url('/img/bg/index_bg.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">MrLee の Blog</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="site-info"><h1 id="site-title">MrLee の Blog</h1><div id="site-subtitle"><span id="subtitle"></span></div><div id="site_social_icons"><a class="social-icon" href="https://github.com/MrLeeqi/" target="_blank" title="Github"><i class="fab fa-github"></i></a></div></div><div id="scroll-down"><i class="fas fa-angle-down scroll-down-effects"></i></div></header><main class="layout" id="content-inner"><div class="recent-posts" id="recent-posts"><div class="recent-post-item"><div class="recent-post-info no-cover"><a class="article-title" href="/2021/09/06/Python%20selenuim%E4%B8%AD%E7%9A%84%E9%97%AE%E9%A2%98/" title="使用selenuim写爬虫时遇到的一些问题及一些常见的配置">使用selenuim写爬虫时遇到的一些问题及一些常见的配置</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-09-06T08:58:15.000Z" title="发表于 2021-09-06 16:58:15">2021-09-06</time></span><span class="article-meta"><span class="article-meta__separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Python/">Python</a></span></div><div class="content">使用selenuim写爬虫时遇到的一些问题及一些常见的配置123456789101112131415161718192021222324252627282930313233from selenium import webdriverchrome_options= webdriver.ChromeOptions()# 浏览器不提供可视化页面. linux下如果系统不支持可视化不加这条会启动失败（隐藏模式）chrome_options.add_argument(&#x27;--headless&#x27;) # 1.解决DevToolsActivePort文件不存在的报错# 2.解决“ERROR:browser_gpu_channel_host_factory.cc(154)] Failed to launch GPU process.”问题# 3.解决”Message: unknown error: unable to discover open pages“问题# 4.解决“unable to discover open window in chrome”问题# 5.解决“Chrome ...</div></div></div><div class="recent-post-item"><div class="recent-post-info no-cover"><a class="article-title" href="/2021/09/06/SQL%20server%E6%9F%A5%E8%AF%A2%E6%9F%90%E4%B8%AA%E5%80%BC%E5%9C%A8%E5%93%AA%E5%BC%A0%E8%A1%A8%E7%9A%84%E5%93%AA%E4%B8%AA%E5%AD%97%E6%AE%B5/" title="SQL server查询某个值在哪张表的哪个字段">SQL server查询某个值在哪张表的哪个字段</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-09-06T08:49:49.000Z" title="发表于 2021-09-06 16:49:49">2021-09-06</time></span><span class="article-meta"><span class="article-meta__separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/SQL-server/">SQL server</a></span></div><div class="content">SQL server查询某个值在哪张表的哪个字段前言当数据库中的表非常多时，我们有时候不清楚某个字段在哪些张表里面，或者知道某个字段的值想要知道哪些表里存在这些值。
解决办法12345678910111213141516171819declare @str varchar(100)set @str&#x3D;&#39;test&#39;  --要搜索的字符串 declare @s varchar(8000)declare tb cursor local forselect s&#x3D;&#39;if exists(select 1 from [&#39;+b.name+&#39;] where [&#39;+a.name+&#39;] like &#39;&#39;%&#39;+@str+&#39;%&#39;&#39;) print &#39;&#39;所在的表及字段: [&#39;+b.name+&#39;].[&#39;+a.name+&#39;]&#39;&#39;&#39;from syscolumns a join sysobjects b on a.id&#x3D;b. ...</div></div></div><div class="recent-post-item"><div class="recent-post-info no-cover"><a class="article-title" href="/2021/09/06/%E8%BF%9C%E7%A8%8B%E8%BF%9E%E6%8E%A5%E6%95%B0%E6%8D%AE%E5%BA%93%E6%8A%A5%E9%94%99/" title="远程连接数据库时报错">远程连接数据库时报错</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-09-06T08:49:16.000Z" title="发表于 2021-09-06 16:49:16">2021-09-06</time></span><span class="article-meta"><span class="article-meta__separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/SQL-Server/">SQL Server</a></span></div><div class="content">远程连接数据库时报错
解决办法1. 修改数据库的端口
打开SQL Server配置管理器
点击SQL Server网络配置
首先必须启用TCP/IP，然后右键点击属性
在IP地址页签，选择IPALL，使此脚本工作
TCP动态端口必须为空
并且TCP端口必须等于：1433（或其它端口）

参考连接：https://stackoverflow.com/questions/49533539/php-sqlsrv-connect-to-sql-server-a-network-related-or-instance-specific-error-h
2. 直接以默认端口连接
通过以上方法查看IPALL中TCP端口号是多少，然后直接IP：端口号直接连接数据库


参考连接：https://blog.csdn.net/taotoxht/article/details/46971757

navicat premium 连接sqlserver 端口号配置
</div></div></div><div class="recent-post-item"><div class="recent-post-info no-cover"><a class="article-title" href="/2021/09/06/JS%20echarts%E5%AE%9E%E7%8E%B0%E6%95%B0%E6%8D%AE%E5%8F%91%E7%94%9F%E5%8F%98%E5%8C%96%E5%9B%BE%E8%A1%A8%E9%87%8D%E6%96%B0%E6%B8%B2%E6%9F%93/" title="echarts实现数据发生变化后图表重新渲染">echarts实现数据发生变化后图表重新渲染</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-09-06T08:41:45.000Z" title="发表于 2021-09-06 16:41:45">2021-09-06</time></span><span class="article-meta"><span class="article-meta__separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/JS/">JS</a></span></div><div class="content">echarts实现数据发生变化后图表重新渲染123if (option &amp;&amp; typeof option === &#x27;object&#x27;) &#123;  myChart.setOption(option, true);  // 添加true后可以重載圖表&#125;


直接在上面代码的option后添加true即可

</div></div></div><div class="recent-post-item"><div class="recent-post-info no-cover"><a class="article-title" href="/2021/09/06/Git%E7%AC%94%E8%AE%B0/" title="Git fork后如何同步源仓库更新&amp;拉取源仓库的指定分支">Git fork后如何同步源仓库更新&amp;拉取源仓库的指定分支</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-09-06T08:40:22.000Z" title="发表于 2021-09-06 16:40:22">2021-09-06</time></span><span class="article-meta"><span class="article-meta__separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Git/">Git</a></span></div><div class="content">Git1.Git fork后如何同步源仓库更新
设置源仓库的远程地址

git remote add [新地址名称] [源仓库远程地址]git remote add zhangsan ssh://git@10.xx.xx.xx:20022/itms2020.git


同步fork

git fetch [新地址名称]git fetch zhangsan


本地切换到想要更新的分支上

git checkout [branch]git checkout feature-pnms


把源仓库的远程分支合并到本地

git merge [新地址名称/分支]git merge zhangsan/feature-pnms


更新到自己的远程库上

git push origin feature-pnms



2.拉取源仓库的指定分支到本地仓库

git checkout -b hotfeature-prm-trackmailtouser zhangsan/hotfeature-prm-trackmailtouser



3. git 删除本地和远程分支
删除本地分支
1git bra ...</div></div></div><div class="recent-post-item"><div class="recent-post-info no-cover"><a class="article-title" href="/2021/09/06/JS%20Ajax%E5%AE%9E%E7%8E%B0%E7%9A%84%E5%8E%9F%E7%90%86--%E4%BA%86%E8%A7%A3%E5%BC%82%E6%AD%A5%E8%AF%B7%E6%B1%82%E5%92%8C%E5%B1%80%E9%83%A8%E5%88%B7%E6%96%B0/" title="Ajax实现的原理--了解异步请求和局部刷新">Ajax实现的原理--了解异步请求和局部刷新</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-09-06T08:39:34.000Z" title="发表于 2021-09-06 16:39:34">2021-09-06</time></span><span class="article-meta"><span class="article-meta__separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/JS/">JS</a></span></div><div class="content">Ajax实现的原理–了解异步请求和局部刷新
AJAX 能做什么
同步请求
异步请求
局部刷新

欢迎大家，经过我看一堆的ajax的文章，今天给大家总结做一个最实用，跟着思路走绝对明白的介绍。
首先我们要知道,AJAX是Asynchronous JavaScript and XML的缩写， 翻译一下“ 平行移动 JavaScript 和 XML ” 想要了解原理，我们首先要知道AJAX能做什么
1. AJAX 能做什么ajax主要是实现页面和web服务器之间数据的异步传输。那么有同学就会问，什么是异步传输？ 异步传输和同步传输相对应，同步传输就是，比如想要访问一个图，图下边有文字，你的浏览器发送了一个请求，在服务器正在解释你的请求，准备给你发文件的时候，你的浏览器会一直等。不会继续加载下边的字，直到拿到这个图片，才会继续加载下边的字。浏览器是直接向服务器发送请求，并直接接收、处理服务器响应的数据的。这就导致了浏览器发送完一个请求后，就只能干等着服务器那边处理请求，响应请求，在这期间其它事情都做不了。而异步请求就是在服务器还没投给你图片的时候，你的浏览器会继续向下工作。把文字加载出来。只要 ...</div></div></div><div class="recent-post-item"><div class="recent-post-info no-cover"><a class="article-title" href="/2021/09/06/Excel%E4%B8%AD%E7%9A%84%E5%90%84%E7%A7%8D%E5%BF%AB%E6%8D%B7%E6%93%8D%E4%BD%9C/" title="excel中的各种快捷操作">excel中的各种快捷操作</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-09-06T08:18:23.000Z" title="发表于 2021-09-06 16:18:23">2021-09-06</time></span><span class="article-meta"><span class="article-meta__separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Excel/">Excel</a></span></div><div class="content">如何在excel中取消合并完单元格后自动把内容填充给其每个取消后的单元格
选中合并区域，取消合并，把合并的取消掉，选定这一列,按下F5，弹出定位对话框，定位条件 选择 空值，确定，按下“=”，再按下向上方向键，再同时按下CTRL+ENTER，就可以了。

</div></div></div><div class="recent-post-item"><div class="recent-post-info no-cover"><a class="article-title" href="/2021/09/06/Django%E6%9F%A5%E7%9C%8BORM%E6%89%A7%E8%A1%8C%E7%9A%84SQL%E8%AF%AD%E5%8F%A5/" title="Django批量删除数据">Django批量删除数据</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-09-06T08:16:33.000Z" title="发表于 2021-09-06 16:16:33">2021-09-06</time></span><span class="article-meta"><span class="article-meta__separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Django/">Django</a></span></div><div class="content">如何查看Django ORM执行的SQL语句
python manage.py shell进入Django提供的数据库访问API
导入from django.db import connection
执行connection.queries，即可查看之前使用Django ORM执行的SQL语句

</div></div></div><div class="recent-post-item"><div class="recent-post-info no-cover"><a class="article-title" href="/2021/09/06/Django%E4%BD%BF%E7%94%A8ORM%E5%AE%9E%E7%8E%B0%E6%95%B0%E6%8D%AE%E5%BA%93%E7%9A%84truncate%E5%88%A0%E8%A1%A8%E5%8A%9F%E8%83%BD/" title="使用Django ORM实现数据库的truncate删表功能">使用Django ORM实现数据库的truncate删表功能</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-09-06T08:15:50.000Z" title="发表于 2021-09-06 16:15:50">2021-09-06</time></span><span class="article-meta"><span class="article-meta__separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Django/">Django</a></span></div><div class="content">使用Django ORM实现数据库的truncate删表功能直接在需要执行truncate功能的模型文件(models.py)中的某个模型下面添加以下代码：
1234567from django.db import connection	# 引入库@classmethoddef truncate(cls):    with connection.cursor() as cursor:        cursor.execute(f&#x27;TRUNCATE TABLE &#123;cls._meta.db_table&#125;;&#x27;)


使用时直接：模型名.truncate()

</div></div></div><div class="recent-post-item"><div class="recent-post-info no-cover"><a class="article-title" href="/2021/05/08/Django%E6%A8%A1%E5%9E%8B%E4%B8%AD%E6%9C%89%E5%A4%96%E9%94%AE%E5%85%B3%E7%B3%BB%E7%9A%84%E8%A1%A8%E5%88%A0%E9%99%A4%E7%9B%B8%E5%85%B3%E8%AE%BE%E7%BD%AE/" title="Django模型中有外键关系的表删除相关设置">Django模型中有外键关系的表删除相关设置</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-05-08T01:00:00.000Z" title="发表于 2021-05-08 09:00:00">2021-05-08</time></span><span class="article-meta"><span class="article-meta__separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Django/">Django</a></span></div><div class="content">django模型中有外键关系的表删除相关设置一、一对一例如有Author、AuthorDetail两表
12345author = models.OneToOneField(to=&#x27;Author&#x27;, null=True,        related_name=&#x27;detail&#x27;,        db_constraint=False,        on_delete=models.CASCADE    )

1）关系字段放在AuthorDetail表中：作者删除详情删除，详情删除作者保留2）作者找详情用 外键related_name(detail)，详情找作者用 外键字段(author)3）db_constraint断开表关联，on_delete规定逻辑关联删除动作，models.CASCADE级联删除
二、一对多例如Book、Publish两表
12345publish = models.ForeignKey(to=&#x27;Publish&#x27;, null=True,        related_name=&#x27;books& ...</div></div></div><nav id="pagination"><div class="pagination"><a class="extend prev" rel="prev" href="/"><i class="fas fa-chevron-left fa-fw"></i></a><a class="page-number" href="/">1</a><span class="page-number current">2</span><a class="page-number" href="/page/3/#content-inner">3</a><a class="page-number" href="/page/4/#content-inner">4</a><a class="extend next" rel="next" href="/page/3/#content-inner"><i class="fas fa-chevron-right fa-fw"></i></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-info-avatar is-center"><img class="avatar-img" data-lazy-src="/img/avatar/avatar.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">MrLee</div><div class="author-info__description">Try harder</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">34</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">35</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">14</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/MrLeeqi/"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/MrLeeqi/" target="_blank" title="Github"><i class="fab fa-github"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">文章会不定期的更新！！！<br>如有疑问，请联系QQ：1012274457</div></div><div class="sticky_layout"></div></div></main><footer id="footer" style="background-image: url('/img/bg/index_bg.jpg')"><div id="footer-wrap"><div class="copyright">&copy;2021 By MrLee</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">Hi, welcome to my <a href="https://amasmrlee.gitee.io">blog</a>!</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="font-plus" type="button" title="放大字体"><i class="fas fa-plus"></i></button><button id="font-minus" type="button" title="缩小字体"><i class="fas fa-minus"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/medium-zoom/dist/medium-zoom.min.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script>function panguFn () {
  if (typeof pangu === 'object') pangu.autoSpacingPage()
  else {
    getScript('https://cdn.jsdelivr.net/npm/pangu/dist/browser/pangu.min.js')
      .then(() => {
        pangu.autoSpacingPage()
      })
  }
}

function panguInit () {
  if (true){
    GLOBAL_CONFIG_SITE.isPost && panguFn()
  } else {
    panguFn()
  }
}

document.addEventListener('DOMContentLoaded', panguInit)</script><script src="/js/search/local-search.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"><script>function subtitleType () {
  fetch('https://v1.hitokoto.cn')
    .then(response => response.json())
    .then(data => {
      if (true) {
        var from = '出自 ' + data.from
        var sub = "永远相信美好的事情即将发生!,Always believe that good things will happen!".length == 0 ? new Array() : "永远相信美好的事情即将发生!,Always believe that good things will happen!".split(',')
        var both = sub.unshift(data.hitokoto, from)
        var typed = new Typed('#subtitle', {
          strings: sub,
          startDelay: 300,
          typeSpeed: 150,
          loop: true,
          backSpeed: 50,
        })
      } else {
        document.getElementById('subtitle').innerHTML = data.hitokoto
      }
    })
}

if (true) {
  if (typeof Typed === 'function') {
    subtitleType()
  } else {
    getScript('https://cdn.jsdelivr.net/npm/typed.js/lib/typed.min.js').then(subtitleType)
  }
} else {
  subtitleType()
}
</script></div><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="true" data-click="true"></script><script id="canvas_nest" defer="defer" color="0,0,255" opacity="0.7" zIndex="-1" count="99" mobile="true" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-nest.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-heart.min.js" async="async" mobile="true"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>